package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.annotation.IsLoginAnno;
import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.domain.RealAuth;
import cn.wolfcode.p2p.base.exception.CustomException;
import cn.wolfcode.p2p.base.query.RealAuthQuery;
import cn.wolfcode.p2p.base.service.IRealAuthService;
import cn.wolfcode.p2p.util.JSONResult;
import cn.wolfcode.p2p.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RealAuthController {
        @Autowired
        private IRealAuthService realAuthService;

        @RequestMapping("realAuth")
        @IsLoginAnno
        public String realAuth(@ModelAttribute("qo")RealAuthQuery qo, Model model){
                PageResult pageResult = realAuthService.query(qo);
                model.addAttribute("pageResult",pageResult);
                return "/realAuth/list";
        }

        @RequestMapping("realAuth_audit")
        @ResponseBody
        public JSONResult realAuthAudit(Long id,String remark,Integer state){
                JSONResult jsonResult = new JSONResult();
                try {
                        realAuthService.audit(id,remark,state);
                    }catch (CustomException e ){
                        jsonResult.setMsg(e.getMessage());//自定义的异常,避免所有异常都返回同样的信息给客户
                    } catch (Exception e) {
                        e.printStackTrace();
                        jsonResult.setMsg("系统繁忙,请稍后再试");
                    }
                 return jsonResult;
        }
}
